package com.socketeg.demo.myThread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;

/**
 * 获取键盘输入bufferedReader  通过socket PrintStream回送消息
 */
public class SendMessage extends Thread {

    BufferedReader bufferedReader;

    PrintStream printStream;

    public SendMessage(BufferedReader bufferedReader, PrintStream printStream) {
        this.bufferedReader = bufferedReader;
        this.printStream = printStream;
    }

    @Override
    public void run() {
        try {
            do {
                String readLine = bufferedReader.readLine();
                System.out.println(readLine);
            } while (true);
        } catch (IOException e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                bufferedReader.close();
                printStream.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
